<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="../../static/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../static/user/css/font.css">
    <link rel="stylesheet" href="../../static/user/css/font.css">
    <link rel="stylesheet" href="../../static/user/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="../../static/user/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/user/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="/dish/dishUI">去点菜</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" placeholder="请输入房间ID查询" id="queryUser" autocomplete="off" class="layui-input">
            <button class="layui-btn" type="button" onclick="queryByName()"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>

    <table class="layui-table">
        <thead>
        <tr>
            <th>序号</th>
            <th>房间号</th>
            <th>菜ID</th>
            <th>菜名</th>
            <th>订单时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tab"></tbody>
    </table>


</div>
<script>
    $(document).ready(init());

    function selectSalary() {
        init();
    }

    function init () {
        //    初始化操作
        selectAll();
    }

    //     查询全部用户
    function selectAll() {
        //    做ajax请求
        $.ajax({
            url:'list',
            dataType:'json',
            type:'post',
            //同步
            async:false,
            success:function (data) {
                console.log(data);
                let dishOrderList = data.dishOrderList;
                $('#showTotal').text('共有数据：' + dishOrderList.length + '条');
                let str = '';//用str变量来拼接用户数据
                for (let i = 0; i < dishOrderList.length; i++) {
                    str += '<tr>' +
                        '<td>' + (i + 1) + '</td>' +
                        '<td>' + dishOrderList[i].roomOrderId + '</td>' +
                        '<td>' + dishOrderList[i].dishId + '</td>' +
                        '<td>' + dishOrderList[i].dishName + '</td>' +
                        '<td>' + dishOrderList[i].orderTime + '</td>' +
                        '<td class="td-maager">' +
                        '<button type="button" onclick="delDishOrder(' + "'" + dishOrderList[i].dishOrderId + "'" + ')">完成订单</button>' +
                        // '<button type="button" onclick="checkSalary('+ "'" + salaryList[i].username + "'" + ')"><i>奖罚详情</i></button>' +
                        '</td>' +
                        '</tr>';
                }
                //html().append()
                $('#tab').html(str);
            }, error: function () {
                alert("服务器错误！");
            }
        })
    }

    function delDishOrder(id) {
        if (confirm("是否真的要删除订单?")) {
            $.ajax({
                url:'del/' + id,
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    let res = data.code;
                    console.log(res);
                    if(res === 200) {
                        alert("删除成功！");
                    } else {
                        alert("删除失败！");
                    }
                }, error: function () {
                    alert("发送失败")
                }
            })
            location.reload();
        }
    }
</script>

</body>
</html>